package com.zfl.mapper;

import com.zfl.dto.query.SeatQuery;
import com.zfl.entity.Seat;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SeatMapper {
    // 普通座位查询（带条件）：用<script>包裹动态SQL
    @Select({
            "<script>", // 新增：开启动态SQL解析
            "SELECT * FROM seat",
            "<where>",
            "   type = 'ORDINARY'", // 固定条件：只查普通座位
            "   <if test='area != null'>AND area = #{area}</if>",
            "   <if test='status != null'>AND status = #{status}</if>",
            "   <if test='hasPower != null'>AND has_power = #{hasPower}</if>",
            "   <if test='isWindow != null'>AND is_window = #{isWindow}</if>",
            "   <if test='seatNo != null'>AND seat_no LIKE CONCAT('%', #{seatNo}, '%')</if>",
            "</where>",
            "</script>" // 新增：结束动态SQL解析
    })
    List<Seat> selectOrdinarySeats(SeatQuery query);

    // 演讲室座位查询（带条件）：用<script>包裹动态SQL
    @Select({
            "<script>", // 新增：开启动态SQL解析
            "SELECT * FROM seat",
            "<where>",
            "   type = 'LECTURE_HALL'", // 固定条件：只查演讲室座位
            "   <if test='area != null'>AND area = #{area}</if>",
            "   <if test='status != null'>AND status = #{status}</if>",
            "   <if test='hasPower != null'>AND has_power = #{hasPower}</if>",
            "   <if test='isWindow != null'>AND is_window = #{isWindow}</if>",
            "   <if test='seatNo != null'>AND seat_no LIKE CONCAT('%', #{seatNo}, '%')</if>",
            "</where>",
            "</script>" // 新增：结束动态SQL解析
    })
    List<Seat> selectLectureSeats(SeatQuery query);

    // 管理员查询所有座位（带条件）：用<script>包裹动态SQL
    @Select({
            "<script>", // 新增：开启动态SQL解析
            "SELECT * FROM seat",
            "<where>",
            "   <if test='area != null'>AND area = #{area}</if>",
            "   <if test='status != null'>AND status = #{status}</if>",
            "   <if test='hasPower != null'>AND has_power = #{hasPower}</if>",
            "   <if test='isWindow != null'>AND is_window = #{isWindow}</if>",
            "   <if test='seatNo != null'>AND seat_no LIKE CONCAT('%', #{seatNo}, '%')</if>",
            "   <if test='type != null'>AND type = #{type}</if>",
            "</where>",
            "</script>" // 新增：结束动态SQL解析
    })
    List<Seat> selectAllSeats(SeatQuery query);
}